<?php 
class AdBookmark extends Object
{
	public $UserId;
	
	public $AdId;
	public $AdTitle;
	
	public $AdTypeId;
	public $AdTypeTitle;
	public $AdCatId;
	public $AdCatTitle;
	public $AdBrandId;
	public $AdBrandTitle;
	
	public $DateCreated;
	
	public $Title;
	public $Active;
	
	public function AdBookmark($values = '')
	{ 
		self::setDataTable('am_ad_bookmarks');
		if(is_array($values))
		{ self::setValues($values); }
	}
	
	public function getUserId() { return intval($this->UserId); }
	public function getAdId() { return intval($this->AdId); }
	public function getAdTypeId() { return intval($this->AdTypeId); }
	public function getAdCatId() { return intval($this->AdCatId); }
	public function getBrandId() { return intval($this->BrandId); }
	
	public function setUserId($val) { $this->UserId=intval($val); }
	public function setAdId($val) { $this->AdId=intval($val); }
	public function setAdTypeId($val) { $this->AdTypeId=intval($val); }
	public function setAdCatId($val) { $this->AdCatId=intval($val); }
	public function setBrandId($val) { $this->BrandId=intval($val); }
	
	public function getDateCreated()
	{ 
		if($format != '')
		{ return self::formatDateTime($this->DateCreated, $format); }
		else
		{ return $this->DateCreated; }
	}
	
	public function getLink()
	{
		$out = '';
		if(self::getAdId() > 0)
		{ $out .= '/ad/'.self::getAdId(); }
		return $out;
	}
	
	function insert()
	{
		global $user;
		if((self::getUserId() > 0) && (self::getAdId() > 0) && ($user->getId() == self::getUserId()))
		{
			$insert = '`UserId`';
			$values = self::getUserId();
			
			$insert .= ', `AdId`';
			$values .= ', '.self::getAdId();
			
			$insert .= ', `AdTypeId`';
			$values .= ', '.self::getAdTypeId();
			
			$insert .= ', `AdCatId`';
			$values .= ', '.self::getAdCatId();
			
			$insert .= ', `AdBrandId`';
			$values .= ', '.self::getAdBrandId();
			
			$insert .= ', `Title`';
			$values .= ', "'.self::formatText(self::getTitle(), 100).'"';
			
			$insert .= ', `DateCreated`';
			$values .= ', NOW()';
			
			$sql  = 'INSERT INTO '.DB_PERFIX.self::getDataTable().' ('.$insert.') '; 
			$sql .= 'VALUES ('.$values.');';
			$result = mysql_query($sql);

			$sql = 'SELECT id FROM '.DB_PERFIX.self::getDataTable().' WHERE `userId`='.self::getUserId().' ORDER BY id DESC LIMIT 1;';
			$result = mysql_query($sql);
			if(mysql_num_rows($result) > 0)
			{
				while($row = mysql_fetch_array($result))
				{ self::setId($row['id']); }
			}
		}
	}
}
?>